/**
* @namespace
* @meta-type namespace
* namespace - The root namespace for Kusog
*/
var ksg = {
	
	/**
	*	@namespace
	* A common collection of usefull helper functions used by Kusog internals.
	*/
    util: {
        svcCall: function (url, success, error, cbId, data, usePOST) {
            var callbackName = cbId;
			var ajaxOptions = { dataType: url.indexOf(':') != -1 ? 'jsonp' : 'json', url: url, data: data, success: success, error: error, jsonpCallback: callbackName };
			if(usePOST == true)
				ajaxOptions["type"] = "POST";
            $.ajax(ajaxOptions);
        },
        isNull: function (i) {
            return (i == null || typeof (i) == 'undefined');
        },
		
        urlParamsId: function () {
            if (urlParams.id != null)
                return urlParams.id;
            return 'NotFound';
        },
		/**
		* The big problem with just checking for window.DOMParser is that IE9 supports that now, but the xml document
		* it returns lacks many things expected in an xml document like selectSingleNode.  However, if we keep using the
		* active x object type, then it works fine.  So now we just check for ie and default to the better xml document
		* type for now.
		* Lots of bug reports for this on web "ie9 missing selectSingleNode"
		*/
        createXmlDoc: function (xml) {
            var xmlDoc = null;
            //if (window.DOMParser) {
			 if(!$.browser.msie) {
                parser = new DOMParser();
                xmlDoc = parser.parseFromString(xml, "text/xml");
            }
            else // Internet Explorer
            {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async = "false";
                xmlDoc.loadXML(xml);
            }
            return xmlDoc;
        },
        createXmlString: function (elem) {
            var serialized;
            try {
                // XMLSerializer exists in current Mozilla browsers
                serializer = new XMLSerializer();
                serialized = serializer.serializeToString(elem);
            }
            catch (e) {
                // Internet Explorer has a different approach to serializing XML
                serialized = elem.xml;
            }

            return serialized;
        }
    },
	
	/**
	*	@namespace
	* namespace - Contains all code items related to the gui portion of the app framework.
	* @meta-type namespace
	*/
	ui: {
	/**
	* @namespace
	* Factory Map of registered bizprocs.
	* @meta-type factory
	*/
		bizprocs:{}
	},
	/**
	* @namespace
	* Map of registered web services that can be called by name.
	*/
	services: {}
};

if(!$.browser.msie) {
    XMLDocument.prototype.selectNodes = function(xpath, contextNode) {
		try {
			if (this.nsResolver == null)
				this.nsResolver = this.createNSResolver(this.documentElement);
	
			var oResult = this.evaluate(xpath, (contextNode?contextNode:this), null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			var nodeList = new Array(oResult.snapshotLength);
			nodeList.expr = xpath;
			var j = 0;
			for (i=0;i<oResult.snapshotLength;i++)
			{
				var item = oResult.snapshotItem(i);
				//	Ignore whitespace nodes.
				if (item.nodeType != 3)
				{
					nodeList[j++] = item;
				}
			}
			return nodeList;
		}catch(e){
		}
    }

    XMLDocument.prototype.selectSingleNode = function(xpath, contextNode) {
        var ar = this.selectNodes(xpath,contextNode);
        if(ar.length > 0)
            return ar[0];
        return null;
    }
}

